package cn.buk.tms.eotms.entity;

import jakarta.persistence.*;
import java.util.Date;

import static cn.buk.common.Constant.PSG_TYPE_ADU;
import static cn.buk.common.Constant.PSG_TYPE_CHD;

@Entity
@Table(name="t242")
public class PnrPassenger {

	public PnrPassenger() {
	}

	public PnrPassenger(int psgNo, String psgName) {
		this.psgNo = psgNo;

		psgName = psgName.trim();
		int idx = psgName.indexOf(" ");
		if (idx < 0) {
			if (psgName.contains("CHD")) {
				this.psgType = PSG_TYPE_CHD;
			} else {
				this.psgType = PSG_TYPE_ADU;
			}
		} else if (psgName.length() > 6){
			//儿童 2-12岁
//        男童  MSTR
//        女童  MISS
//        其他一般统一加CHD
			String temp = psgName.substring(psgName.length()-4).trim();
			if ("CHD".equalsIgnoreCase(temp)) {
				this.psgType = PSG_TYPE_CHD;
			} else if("MSTR".equalsIgnoreCase(temp)) {
				this.psgType = PSG_TYPE_CHD;
			} else if("MISS".equalsIgnoreCase(temp)) {
				this.psgType = PSG_TYPE_CHD;
			}
		}

		this.selected = true;

		this.psgName = psgName;
	}

	@Id
	@GeneratedValue(strategy= GenerationType.IDENTITY)
	private int id;
	
	@ManyToOne
	@JoinColumn(name="pnrid")
	private Pnr pnr;
	
	/**
	 * 乘机人序号
	 */
	@Column(name="psgOrd")
	private int sn;
	
	@Column(length=40)
	private String firstName;
	
	@Column(length=30)
	private String lastName;

    @Column(length=40)
    private String psgName;

	/**
	 * 乘机人类型：成人，儿童，婴儿
	 * 0 - ADT - adult
	 * 1 - CHD - child
	 * 2 - INF - infant
	 */
	@Column(name = "psg_type")
	private Integer psgType;

	/**
	 * null/-1 未填写
	 * 1 - 男
	 * 2 - 女
	 */
	private Integer gender;

	@Transient
	private Date birthday;

	/**
	 * 证件类型
	 * 	/**
	 * 1-身份证
	 * 2-护照
	 */
	@Column(name="id_type")
	private Integer idType;

	/**
	 * 证件号
	 */
	@Column(name = "id_no", length=30)
	private String idNo;

	/**
	 * 证件有效期
	 */
	@Transient
	private Date idExpiredDate;

	/**
	 * 国籍：2位或三位代码
	 */
	@Transient
	private String nationality;

	/**
	 * 保存pnr中针对某人的fn项目
	 */
	
	@Transient
	private String fn;

    @Transient
    private String patA;

	/**
	 * 在pnr中名字对应的前面的数字
	 */
	@Transient
	private int psgNo;

	@Transient
	private String ticketNo;

	/**
	 * 随行婴儿名
	 */
	@Transient
	private String infName;

	/**
	 * 随行婴儿票号
	 */
	@Transient
	private String infTicketNo;

	/**
	 * 联系手机
	 */
	@Transient
	private String mobile;

	/**
	 * 常旅客号，PNR中有航司的，所以此常旅客号表示对应航司的
	 */
	@Transient
	private String ffpNo;

	@Transient
	private boolean selected;

	public String getName() {
		return this.psgName;
	}

	/**
	 * @return the pnr
	 */
	public Pnr getPnr() {
		return pnr;
	}

	/**
	 * @param pnr the pnr to set
	 */
	public void setPnr(Pnr pnr) {
		this.pnr = pnr;
	}

	/**
	 * @return the sn
	 */
	public int getSn() {
		return sn;
	}

	/**
	 * @param sn the sn to set
	 */
	public void setSn(int sn) {
		this.sn = sn;
	}

	/**
	 * @return the firstName
	 */
	public String getFirstName() {
        if (this.firstName == null ) {
            this.firstName = this.psgName; //for compliant with plutus
        }
		return firstName;
	}

	/**
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	/**
	 * @return the idNo
	 */
	public String getIdNo() {
		return idNo == null ? "": idNo.trim().toUpperCase();
	}

	/**
	 * @param idNo the idNo to set
	 */
	public void setIdNo(String idNo) {
		this.idNo = idNo;
	}

	/**
	 * @return the fn
	 */
	public String getFn() {
		return fn;
	}

	/**
	 * @param fn the fn to set
	 */
	public void setFn(String fn) {
		this.fn = fn;
	}

    public String getPsgName() {
        return psgName == null ? "" : psgName.trim();
    }

    public void setPsgName(String psgName) {
        this.psgName = psgName;
    }

    public String getPatA() {
        return patA;
    }

    public void setPatA(String patA) {
        this.patA = patA;
    }

	public int getPsgNo() {
		return psgNo;
	}

	public void setPsgNo(int psgNo) {
		this.psgNo = psgNo;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTicketNo() {
		return ticketNo;
	}

	public void setTicketNo(String ticketNo) {
		this.ticketNo = ticketNo;
	}

	public String getInfName() {
		return infName;
	}

	public void setInfName(String infName) {
		this.infName = infName;
	}

	public String getInfTicketNo() {
		return infTicketNo;
	}

	public void setInfTicketNo(String infTicketNo) {
		this.infTicketNo = infTicketNo;
	}

	public Integer getIdType() {
		return idType == null ? 0 : idType;
	}

	public void setIdType(Integer idType) {
		this.idType = idType;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getFfpNo() {
		return ffpNo;
	}

	public void setFfpNo(String ffpNo) {
		this.ffpNo = ffpNo;
	}

	public int getPsgType() {
		return psgType == null ? 0 : psgType;
	}

	public void setPsgType(Integer passengerType) {
		this.psgType = passengerType;
	}

	public int getGender() {
		return gender == null ? -1 : gender;
	}

	public void setGender(Integer gender) {
		this.gender = gender;
	}

	public String getNationality() {
		return nationality;
	}

	public void setNationality(String nationality) {
		this.nationality = nationality;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}

	public Date getIdExpiredDate() {
		return idExpiredDate;
	}

	public void setIdExpiredDate(Date idExpiredDate) {
		this.idExpiredDate = idExpiredDate;
	}
}
